export LANGUAGE=en_US
groupadd -r redis && useradd -r -g redis redis &&\
set -ex; \
	\
	fetchDeps='ca-certificates wget'; \
	apt-get update; \
	apt-get install -y --no-install-recommends $fetchDeps; \
	rm -rf /var/lib/apt/lists/*; \
	\
	dpkgArch="$(dpkg --print-architecture | awk -F- '{ print $NF }')"; \
	wget -O /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/1.10/gosu-$dpkgArch"; \
	wget -O /usr/local/bin/gosu.asc "https://github.com/tianon/gosu/releases/download/1.10/gosu-$dpkgArch.asc"; \
	export GNUPGHOME="$(mktemp -d)"; \
	gpg --keyserver ha.pool.sks-keyservers.net --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4; \
	gpg --batch --verify /usr/local/bin/gosu.asc /usr/local/bin/gosu; \
	rm -r "$GNUPGHOME" /usr/local/bin/gosu.asc; \
	chmod +x /usr/local/bin/gosu; \
	gosu nobody true; \
	\
	apt-get purge -y --auto-remove $fetchDeps
# disable Redis protected mode [1] as it is unnecessary in context of Docker
# (ports are not automatically exposed when running inside Docker, but rather explicitly by specifying -p / -P)
# [1]: https://github.com/antirez/redis/commit/edd4d555df57dc84265fdfb4ef59a4678832f6da
	grep -q '^#define CONFIG_DEFAULT_PROTECTED_MODE 1$' /usr/src/redis/src/server.h; \
	sed -ri 's!^(#define CONFIG_DEFAULT_PROTECTED_MODE) 1$!\1 0!' /usr/src/redis/src/server.h; \
	grep -q '^#define CONFIG_DEFAULT_PROTECTED_MODE 0$' /usr/src/redis/src/server.h; \
# for future reference, we modify this directly in the source instead of just supplying a default configuration flag because apparently "if you specify any argument to redis-server, [it assumes] you are going to specify everything"
# see also https://github.com/docker-library/redis/issues/4#issuecomment-50780840
# (more exactly, this makes sure the default behavior of "save on SIGTERM" stays functional by default)
	\
	make -C /usr/src/redis -j "$(nproc)"; \
	make -C /usr/src/redis install; \
	\
	rm -r /usr/src/redis; \
	\
	apt-get purge -y --auto-remove $buildDeps

mkdir /data && chown redis:redis /data
cp docker-entrypoint.sh /usr/local/bin/

set -ex; \

	apt-get update; \
	apt-get install -y wget gcc libc6-dev make --no-install-recommends; \
	rm -rf /var/lib/apt/lists/*; \
	\
	wget -O redis.tar.gz "http://download.redis.io/releases/redis-3.2.11.tar.gz"; \
	echo "31ae927cab09f90c9ca5954aab7aeecc3bb4da6087d3d12ba0a929ceb54081b5 *redis.tar.gz" | sha256sum -c -; \
	mkdir -p /usr/src/redis; \
	tar -xzf redis.tar.gz -C /usr/src/redis --strip-components=1; \
	rm redis.tar.gz; \
	\


apt-get update  && \
    apt-get install -y \
      net-tools supervisor ruby rubygems locales gettext-base wget && \
    apt-get clean &&\

     apt-get install -y gcc make g++ build-essential libc6-dev tcl git supervisor ruby &&\
      wget -qO redis.tar.gz http://download.redis.io/releases/redis-3.2.11.tar.gz \
    && tar xfz redis.tar.gz -C / \
    && rm -rf /redis&& mv /redis-3.2.11 /redis
cd /redis && make &&\

rm -rf /redis-conf && mkdir /redis-conf &&\

mkdir /redis-data &&\
cp  /root/install/docker-data/redis-cluster.tmpl /redis-conf/redis-cluster.tmpl &&\
cp /root/install/docker-data/redis.tmpl /redis-conf/redis.tmpl &&\
cp /root/install/docker-data/supervisord.conf /etc/supervisor/conf.d/supervisord.conf &&\
cp /root/install/docker-data/docker-entrypoint.sh /docker-entrypoint.sh &&\
chmod 755 /docker-entrypoint.sh &&\
sh /docker-entrypoint.sh
